<template>
  <div class="app-container">
    <el-dialog :title="title" :visible.sync="visible" width="600px" v-if="visible" append-to-body
      :close-on-click-modal="false">
      <el-form ref="form" :model="form" :rules="rules" :label-width="labelWidth">
        <el-form-item label="手机号码：" prop="phone">
          <el-input v-model="form.phone" placeholder="请填写手机号码" size="small" :style="{width: inputWidth}"></el-input>
          <el-button type="primary" icon="el-icon-search" size="small" style="margin-left: 20px" :loading="queryLoading"
            @click="handleQuery">查询
          </el-button>
        </el-form-item>
        <div v-if="info.name">
          <el-form-item label="接收人姓名：">
            <span>{{info.name}}</span>
          </el-form-item>
          <el-form-item label="接收人钱包地址：">
            <span>{{info.address}}</span>
          </el-form-item>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" :disabled="disabled" :loading="submitLoading">确认转增</el-button>
        <el-button @click="cancel">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import {
    shenyeAccountCustomerDDc,
    shenyeAccountDonation
  } from "@/api/equityManager/sYAccountManagement";

  export default {
    // dicts: ['asset_card_type'],
    name: "Dialog",
    data() {
      return {
        labelWidth: '140px',
        inputWidth: '260px',
        id: '', //
        queryLoading: false,
        // 是否禁用表单
        disabled: true,
        // 弹出层标题
        title: "转增",
        // 是否显示弹出层
        visible: false,
        submitLoading: false,
        info: {},
        // 表单参数
        form: {
          phone: '', //手机号
        },
        // 表单校验
        rules: {
          phone: [{
            required: true,
            message: "请填写手机号码",
            trigger: ["blur", "change"]
          }],
        },
      };
    },
    created() {

    },
    methods: {
      /** 打开发行管理弹框 */
      open(id) {
        this.reset();
        this.id = id
        this.visible = true
      },
      // 取消按钮
      cancel() {
        this.visible = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
            phone: '',
          },
          this.info = {}
        this.disabled = true
      },
      //查询查询用户ddc区块链信息
      handleQuery() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            this.queryLoading = true
            let data = {
              ...this.form
            }
            shenyeAccountCustomerDDc(data).then(res => {
              this.info = res.result
              this.disabled = false
              this.queryLoading = false
            }).catch(() => {
              this.queryLoading = false
            })
          }
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.submitLoading = true
        let data = {
          customerEquityCardId: this.id,
          toCustomerId: this.info.id
        }
        shenyeAccountDonation(data).then(res => {
          this.$message.success('操作成功');
          this.cancel();
          this.$emit('refresh')
          this.submitLoading = false
        }).catch(() => {
          this.submitLoading = false
        })
      },
      /** 序号 */
      rowIndex({
        row,
        rowIndex
      }) {
        row.index = rowIndex + 1;
      },
    }
  };

</script>
<style scoped>
  .img_box {
    width: 100px;
    height: 70px;
    border-radius: 4px;
  }

</style>
